package com.dragon.client.controller.supplies;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.supplies.IWarehouseInoutService;
import com.dragon.repository.domain.dto.WarehouseInoutDTO;
import com.dragon.repository.domain.vo.WarehouseInoutVO;
import com.dragon.repository.entity.WarehouseInout;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 出入库 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-11-14
 */
@RestController
@RequestMapping("warehouseInout")
@Api(tags = "出入库")
public class WarehouseInoutController {

    @Autowired
    IWarehouseInoutService service;

    @GetMapping("inoutList")
    @ApiOperation(value = "出入库列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int"),
            @ApiImplicitParam(name = "inoutType", value = "出入库类型", required = false, type = "int"),
            @ApiImplicitParam(name = "type", value = "类型", required = false, type = "int"),
            @ApiImplicitParam(name = "id", value = "id", required = false, type = "int")
    })
    public ResponseData<List<WarehouseInoutDTO>> inoutList(@RequestParam Integer page,
                                                           @RequestParam Integer limit,
                                                           @RequestParam(required = false) Integer inoutType,
                                                           @RequestParam(required = false) Integer type,
                                                           @RequestParam(required = false) Integer id) {
        Page<WarehouseInout> warehouseInoutPage = service.inoutList(page, limit, inoutType, type, id);
        return ResponseData.success(WarehouseInoutDTO.convertList(warehouseInoutPage.getRecords()), warehouseInoutPage.getTotal());
    }

    @PostMapping("updateInout")
    @ApiOperation(value = "修改出入库子表")
    public ResponseData updateInout(@RequestBody @Validated(Update.class) WarehouseInoutVO vo ){
        service.updateInout(WarehouseInoutVO.convert(vo));
        return ResponseData.success();
    }


    @PostMapping("confirmInout")
    @ApiOperation(value = "确认出入库")
    public ResponseData confirmInout(Integer id) {
        service.confirmInout(id);
        return ResponseData.success();
    }

}
